{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "path = './origin_dataset.csv'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>category</th>\n",
       "      <th>main_category</th>\n",
       "      <th>currency</th>\n",
       "      <th>deadline</th>\n",
       "      <th>goal</th>\n",
       "      <th>launched</th>\n",
       "      <th>pledged</th>\n",
       "      <th>state</th>\n",
       "      <th>country</th>\n",
       "      <th>usd_pledged_real</th>\n",
       "      <th>usd_goal_real</th>\n",
       "      <th>Unnamed: 12</th>\n",
       "      <th>Unnamed: 13</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>The Songs of Adelaide &amp; Abullah</td>\n",
       "      <td>Poetry</td>\n",
       "      <td>Publishing</td>\n",
       "      <td>GBP</td>\n",
       "      <td>2015/10/9</td>\n",
       "      <td>1000</td>\n",
       "      <td>2015/8/11 12:12</td>\n",
       "      <td>0</td>\n",
       "      <td>failed</td>\n",
       "      <td>GB</td>\n",
       "      <td>0</td>\n",
       "      <td>1533.95</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Greeting From Earth: ZGAC Arts Capsule For ET</td>\n",
       "      <td>Narrative Film</td>\n",
       "      <td>Film &amp; Video</td>\n",
       "      <td>USD</td>\n",
       "      <td>2017/11/1</td>\n",
       "      <td>30000</td>\n",
       "      <td>2017/9/2 4:43</td>\n",
       "      <td>2421</td>\n",
       "      <td>failed</td>\n",
       "      <td>US</td>\n",
       "      <td>2421</td>\n",
       "      <td>30000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Where is Hank?</td>\n",
       "      <td>Narrative Film</td>\n",
       "      <td>Film &amp; Video</td>\n",
       "      <td>USD</td>\n",
       "      <td>2013/2/26</td>\n",
       "      <td>45000</td>\n",
       "      <td>2013/1/12 0:20</td>\n",
       "      <td>220</td>\n",
       "      <td>failed</td>\n",
       "      <td>US</td>\n",
       "      <td>220</td>\n",
       "      <td>45000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>ToshiCapital Rekordz Needs Help to Complete Album</td>\n",
       "      <td>Music</td>\n",
       "      <td>Music</td>\n",
       "      <td>USD</td>\n",
       "      <td>2012/4/16</td>\n",
       "      <td>5000</td>\n",
       "      <td>2012/3/17 3:24</td>\n",
       "      <td>1</td>\n",
       "      <td>failed</td>\n",
       "      <td>US</td>\n",
       "      <td>1</td>\n",
       "      <td>5000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Community Film Project: The Art of Neighborhoo...</td>\n",
       "      <td>Film &amp; Video</td>\n",
       "      <td>Film &amp; Video</td>\n",
       "      <td>USD</td>\n",
       "      <td>2015/8/29</td>\n",
       "      <td>19500</td>\n",
       "      <td>2015/7/4 8:35</td>\n",
       "      <td>1283</td>\n",
       "      <td>canceled</td>\n",
       "      <td>US</td>\n",
       "      <td>1283</td>\n",
       "      <td>19500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                name        category  \\\n",
       "0                    The Songs of Adelaide & Abullah          Poetry   \n",
       "1      Greeting From Earth: ZGAC Arts Capsule For ET  Narrative Film   \n",
       "2                                     Where is Hank?  Narrative Film   \n",
       "3  ToshiCapital Rekordz Needs Help to Complete Album           Music   \n",
       "4  Community Film Project: The Art of Neighborhoo...    Film & Video   \n",
       "\n",
       "  main_category currency   deadline   goal         launched pledged     state  \\\n",
       "0    Publishing      GBP  2015/10/9   1000  2015/8/11 12:12       0    failed   \n",
       "1  Film & Video      USD  2017/11/1  30000    2017/9/2 4:43    2421    failed   \n",
       "2  Film & Video      USD  2013/2/26  45000   2013/1/12 0:20     220    failed   \n",
       "3         Music      USD  2012/4/16   5000   2012/3/17 3:24       1    failed   \n",
       "4  Film & Video      USD  2015/8/29  19500    2015/7/4 8:35    1283  canceled   \n",
       "\n",
       "  country usd_pledged_real usd_goal_real Unnamed: 12 Unnamed: 13  \n",
       "0      GB                0       1533.95         NaN         NaN  \n",
       "1      US             2421         30000         NaN         NaN  \n",
       "2      US              220         45000         NaN         NaN  \n",
       "3      US                1          5000         NaN         NaN  \n",
       "4      US             1283         19500         NaN         NaN  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataset = pd.read_csv(path, encoding='ANSI', dtype=object)\n",
    "\n",
    "dataset.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>category</th>\n",
       "      <th>main_category</th>\n",
       "      <th>currency</th>\n",
       "      <th>deadline</th>\n",
       "      <th>goal</th>\n",
       "      <th>launched</th>\n",
       "      <th>pledged</th>\n",
       "      <th>state</th>\n",
       "      <th>country</th>\n",
       "      <th>usd_pledged_real</th>\n",
       "      <th>usd_goal_real</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>The Songs of Adelaide &amp; Abullah</td>\n",
       "      <td>Poetry</td>\n",
       "      <td>Publishing</td>\n",
       "      <td>GBP</td>\n",
       "      <td>2015/10/9</td>\n",
       "      <td>1000</td>\n",
       "      <td>2015/8/11 12:12</td>\n",
       "      <td>0</td>\n",
       "      <td>failed</td>\n",
       "      <td>GB</td>\n",
       "      <td>0</td>\n",
       "      <td>1533.95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Greeting From Earth: ZGAC Arts Capsule For ET</td>\n",
       "      <td>Narrative Film</td>\n",
       "      <td>Film &amp; Video</td>\n",
       "      <td>USD</td>\n",
       "      <td>2017/11/1</td>\n",
       "      <td>30000</td>\n",
       "      <td>2017/9/2 4:43</td>\n",
       "      <td>2421</td>\n",
       "      <td>failed</td>\n",
       "      <td>US</td>\n",
       "      <td>2421</td>\n",
       "      <td>30000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Where is Hank?</td>\n",
       "      <td>Narrative Film</td>\n",
       "      <td>Film &amp; Video</td>\n",
       "      <td>USD</td>\n",
       "      <td>2013/2/26</td>\n",
       "      <td>45000</td>\n",
       "      <td>2013/1/12 0:20</td>\n",
       "      <td>220</td>\n",
       "      <td>failed</td>\n",
       "      <td>US</td>\n",
       "      <td>220</td>\n",
       "      <td>45000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>ToshiCapital Rekordz Needs Help to Complete Album</td>\n",
       "      <td>Music</td>\n",
       "      <td>Music</td>\n",
       "      <td>USD</td>\n",
       "      <td>2012/4/16</td>\n",
       "      <td>5000</td>\n",
       "      <td>2012/3/17 3:24</td>\n",
       "      <td>1</td>\n",
       "      <td>failed</td>\n",
       "      <td>US</td>\n",
       "      <td>1</td>\n",
       "      <td>5000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Community Film Project: The Art of Neighborhoo...</td>\n",
       "      <td>Film &amp; Video</td>\n",
       "      <td>Film &amp; Video</td>\n",
       "      <td>USD</td>\n",
       "      <td>2015/8/29</td>\n",
       "      <td>19500</td>\n",
       "      <td>2015/7/4 8:35</td>\n",
       "      <td>1283</td>\n",
       "      <td>canceled</td>\n",
       "      <td>US</td>\n",
       "      <td>1283</td>\n",
       "      <td>19500</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                name        category  \\\n",
       "0                    The Songs of Adelaide & Abullah          Poetry   \n",
       "1      Greeting From Earth: ZGAC Arts Capsule For ET  Narrative Film   \n",
       "2                                     Where is Hank?  Narrative Film   \n",
       "3  ToshiCapital Rekordz Needs Help to Complete Album           Music   \n",
       "4  Community Film Project: The Art of Neighborhoo...    Film & Video   \n",
       "\n",
       "  main_category currency   deadline   goal         launched pledged     state  \\\n",
       "0    Publishing      GBP  2015/10/9   1000  2015/8/11 12:12       0    failed   \n",
       "1  Film & Video      USD  2017/11/1  30000    2017/9/2 4:43    2421    failed   \n",
       "2  Film & Video      USD  2013/2/26  45000   2013/1/12 0:20     220    failed   \n",
       "3         Music      USD  2012/4/16   5000   2012/3/17 3:24       1    failed   \n",
       "4  Film & Video      USD  2015/8/29  19500    2015/7/4 8:35    1283  canceled   \n",
       "\n",
       "  country usd_pledged_real usd_goal_real  \n",
       "0      GB                0       1533.95  \n",
       "1      US             2421         30000  \n",
       "2      US              220         45000  \n",
       "3      US                1          5000  \n",
       "4      US             1283         19500  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# delete Unnamed col\n",
    "# because unknown error\n",
    "dataset = dataset.drop(columns=['Unnamed: 12','Unnamed: 13'],axis=1)\n",
    "\n",
    "# limit the value range of state to [failed, canceled, successful, live, suspended]\n",
    "# because dislocation error\n",
    "dataset = dataset.loc[dataset['state'].isin(['failed','canceled','successful','live','suspended'])]\n",
    "\n",
    "# rename N,0\" to NO in country col\n",
    "dataset.loc[dataset['country'] == 'N,0\"', 'country'] = 'NO'\n",
    "\n",
    "dataset.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "dataset.to_csv('./dataset.csv', index=True, index_label='origin_id')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>origin_id</th>\n",
       "      <th>name</th>\n",
       "      <th>category</th>\n",
       "      <th>main_category</th>\n",
       "      <th>currency</th>\n",
       "      <th>deadline</th>\n",
       "      <th>goal</th>\n",
       "      <th>launched</th>\n",
       "      <th>pledged</th>\n",
       "      <th>state</th>\n",
       "      <th>country</th>\n",
       "      <th>usd_pledged_real</th>\n",
       "      <th>usd_goal_real</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>The Songs of Adelaide &amp; Abullah</td>\n",
       "      <td>Poetry</td>\n",
       "      <td>Publishing</td>\n",
       "      <td>GBP</td>\n",
       "      <td>2015/10/9</td>\n",
       "      <td>1000</td>\n",
       "      <td>2015/8/11 12:12</td>\n",
       "      <td>0</td>\n",
       "      <td>failed</td>\n",
       "      <td>GB</td>\n",
       "      <td>0</td>\n",
       "      <td>1533.95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>Greeting From Earth: ZGAC Arts Capsule For ET</td>\n",
       "      <td>Narrative Film</td>\n",
       "      <td>Film &amp; Video</td>\n",
       "      <td>USD</td>\n",
       "      <td>2017/11/1</td>\n",
       "      <td>30000</td>\n",
       "      <td>2017/9/2 4:43</td>\n",
       "      <td>2421</td>\n",
       "      <td>failed</td>\n",
       "      <td>US</td>\n",
       "      <td>2421</td>\n",
       "      <td>30000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>Where is Hank?</td>\n",
       "      <td>Narrative Film</td>\n",
       "      <td>Film &amp; Video</td>\n",
       "      <td>USD</td>\n",
       "      <td>2013/2/26</td>\n",
       "      <td>45000</td>\n",
       "      <td>2013/1/12 0:20</td>\n",
       "      <td>220</td>\n",
       "      <td>failed</td>\n",
       "      <td>US</td>\n",
       "      <td>220</td>\n",
       "      <td>45000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>ToshiCapital Rekordz Needs Help to Complete Album</td>\n",
       "      <td>Music</td>\n",
       "      <td>Music</td>\n",
       "      <td>USD</td>\n",
       "      <td>2012/4/16</td>\n",
       "      <td>5000</td>\n",
       "      <td>2012/3/17 3:24</td>\n",
       "      <td>1</td>\n",
       "      <td>failed</td>\n",
       "      <td>US</td>\n",
       "      <td>1</td>\n",
       "      <td>5000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>Community Film Project: The Art of Neighborhoo...</td>\n",
       "      <td>Film &amp; Video</td>\n",
       "      <td>Film &amp; Video</td>\n",
       "      <td>USD</td>\n",
       "      <td>2015/8/29</td>\n",
       "      <td>19500</td>\n",
       "      <td>2015/7/4 8:35</td>\n",
       "      <td>1283</td>\n",
       "      <td>canceled</td>\n",
       "      <td>US</td>\n",
       "      <td>1283</td>\n",
       "      <td>19500</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  origin_id                                               name  \\\n",
       "0         0                    The Songs of Adelaide & Abullah   \n",
       "1         1      Greeting From Earth: ZGAC Arts Capsule For ET   \n",
       "2         2                                     Where is Hank?   \n",
       "3         3  ToshiCapital Rekordz Needs Help to Complete Album   \n",
       "4         4  Community Film Project: The Art of Neighborhoo...   \n",
       "\n",
       "         category main_category currency   deadline   goal         launched  \\\n",
       "0          Poetry    Publishing      GBP  2015/10/9   1000  2015/8/11 12:12   \n",
       "1  Narrative Film  Film & Video      USD  2017/11/1  30000    2017/9/2 4:43   \n",
       "2  Narrative Film  Film & Video      USD  2013/2/26  45000   2013/1/12 0:20   \n",
       "3           Music         Music      USD  2012/4/16   5000   2012/3/17 3:24   \n",
       "4    Film & Video  Film & Video      USD  2015/8/29  19500    2015/7/4 8:35   \n",
       "\n",
       "  pledged     state country usd_pledged_real usd_goal_real  \n",
       "0       0    failed      GB                0       1533.95  \n",
       "1    2421    failed      US             2421         30000  \n",
       "2     220    failed      US              220         45000  \n",
       "3       1    failed      US                1          5000  \n",
       "4    1283  canceled      US             1283         19500  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataset = pd.read_csv('./dataset.csv', dtype=object)\n",
    "\n",
    "dataset.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>origin_id</th>\n",
       "      <th>category</th>\n",
       "      <th>currency</th>\n",
       "      <th>state</th>\n",
       "      <th>country</th>\n",
       "      <th>pledged</th>\n",
       "      <th>goal</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>Publishing</td>\n",
       "      <td>GBP</td>\n",
       "      <td>failed</td>\n",
       "      <td>GB</td>\n",
       "      <td>0</td>\n",
       "      <td>1533.95</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>Film &amp; Video</td>\n",
       "      <td>USD</td>\n",
       "      <td>failed</td>\n",
       "      <td>US</td>\n",
       "      <td>2421</td>\n",
       "      <td>30000</td>\n",
       "      <td>2017</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>Film &amp; Video</td>\n",
       "      <td>USD</td>\n",
       "      <td>failed</td>\n",
       "      <td>US</td>\n",
       "      <td>220</td>\n",
       "      <td>45000</td>\n",
       "      <td>2013</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>Music</td>\n",
       "      <td>USD</td>\n",
       "      <td>failed</td>\n",
       "      <td>US</td>\n",
       "      <td>1</td>\n",
       "      <td>5000</td>\n",
       "      <td>2012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>Film &amp; Video</td>\n",
       "      <td>USD</td>\n",
       "      <td>canceled</td>\n",
       "      <td>US</td>\n",
       "      <td>1283</td>\n",
       "      <td>19500</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  origin_id      category currency     state country pledged     goal  year\n",
       "0         0    Publishing      GBP    failed      GB       0  1533.95  2015\n",
       "1         1  Film & Video      USD    failed      US    2421    30000  2017\n",
       "2         2  Film & Video      USD    failed      US     220    45000  2013\n",
       "3         3         Music      USD    failed      US       1     5000  2012\n",
       "4         4  Film & Video      USD  canceled      US    1283    19500  2015"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# delete name col\n",
    "# because it is useless for prediction\n",
    "dataset = dataset.drop(columns=['name'],axis=1)\n",
    "\n",
    "# merge deadline and launched to year\n",
    "dataset['year'] = dataset['launched'].str[0:4]\n",
    "dataset = dataset.drop(columns=['deadline', 'launched'],axis=1)\n",
    "\n",
    "# merge category and main_category to category\n",
    "dataset = dataset.drop(columns=['category'],axis=1)\n",
    "dataset = dataset.rename(columns={'main_category':'category'})\n",
    "\n",
    "# update goal and pledged\n",
    "dataset = dataset.drop(columns=['goal', 'pledged'],axis=1)\n",
    "dataset = dataset.rename(columns={'usd_pledged_real':'pledged', 'usd_goal_real':'goal'})\n",
    "\n",
    "dataset.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "dataset.to_csv('./mid_dataset.csv', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'Publishing': 0, 'Film & Video': 1, 'Music': 2, 'Food': 3, 'Design': 4, 'Crafts': 5, 'Games': 6, 'Comics': 7, 'Fashion': 8, 'Theater': 9, 'Art': 10, 'Photography': 11, 'Technology': 12, 'Dance': 13, 'Journalism': 14}\n",
      "{'GBP': 0, 'USD': 1, 'CAD': 2, 'AUD': 3, 'NOK': 4, 'EUR': 5, 'MXN': 6, 'SEK': 7, 'NZD': 8, 'CHF': 9, 'DKK': 10, 'HKD': 11, 'SGD': 12, 'JPY': 13}\n",
      "{'failed': 0, 'canceled': 1, 'successful': 2, 'live': 3, 'suspended': 4}\n",
      "{'GB': 0, 'US': 1, 'CA': 2, 'AU': 3, 'NO': 4, 'IT': 5, 'DE': 6, 'IE': 7, 'MX': 8, 'ES': 9, 'SE': 10, 'FR': 11, 'NL': 12, 'NZ': 13, 'CH': 14, 'AT': 15, 'DK': 16, 'BE': 17, 'HK': 18, 'LU': 19, 'SG': 20, 'JP': 21}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>origin_id</th>\n",
       "      <th>category</th>\n",
       "      <th>currency</th>\n",
       "      <th>state</th>\n",
       "      <th>country</th>\n",
       "      <th>pledged</th>\n",
       "      <th>goal</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1533.95</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2421.0</td>\n",
       "      <td>30000.00</td>\n",
       "      <td>2017</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>220.0</td>\n",
       "      <td>45000.00</td>\n",
       "      <td>2013</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5000.00</td>\n",
       "      <td>2012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1283.0</td>\n",
       "      <td>19500.00</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  origin_id  category  currency  state  country  pledged      goal  year\n",
       "0         0         0         0      0        0      0.0   1533.95  2015\n",
       "1         1         1         1      0        1   2421.0  30000.00  2017\n",
       "2         2         1         1      0        1    220.0  45000.00  2013\n",
       "3         3         2         1      0        1      1.0   5000.00  2012\n",
       "4         4         1         1      1        1   1283.0  19500.00  2015"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# transform datatype\n",
    "\n",
    "cols = ['category', 'currency', 'state', 'country']\n",
    "\n",
    "for col in cols:\n",
    "    rg = dataset[col].unique()\n",
    "    mapping = {}\n",
    "    for idx,val in enumerate(rg):\n",
    "        dataset.loc[dataset[col] == val, col] = idx\n",
    "        mapping[val] = idx\n",
    "    dataset[col] = dataset[col].astype(int)\n",
    "    print(mapping)\n",
    "\n",
    "dataset['goal'] = dataset['goal'].astype(float)\n",
    "dataset['pledged'] = dataset['pledged'].astype(float)\n",
    "dataset['year'] = dataset['year'].astype(int)\n",
    "\n",
    "dataset.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "dataset.to_csv('./final_dataset.csv', index=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
